package com.sywb.chuangyebao.view.dialog;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.sywb.chuangyebao.R;
import com.sywb.chuangyebao.utils.Utils;
import com.sywb.chuangyebao.view.AskActivity;
import com.sywb.chuangyebao.view.PublishArticleActivity;
import com.sywb.chuangyebao.view.PublishVideoActivity;

import butterknife.OnClick;

/**
 * 主页发布选项对话框
 * Created by duxl on 2018/5/16.
 */

public class MainPublishDialog extends BaseDialogFragment {

    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.dialog_main_publish;
    }


    public static MainPublishDialog newInstance() {
        MainPublishDialog dialogFragment = new MainPublishDialog();
        Bundle bundle = new Bundle();
        //bundle.putSerializable("title", title);
        dialogFragment.setArguments(bundle);
        return dialogFragment;
    }

    @Override
    public void initView(View view, Bundle bundle) {
        if (bundle == null) {
            bundle = getArguments();
        }

        //title = bundle.getString("title");

        getDialog().getWindow().setGravity(Gravity.BOTTOM);
//        getDialog().setCancelable(false);
//        getDialog().setCanceledOnTouchOutside(false);
//        getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
//            @Override
//            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
//                if (keyCode == KeyEvent.KEYCODE_BACK) {
//                    return true;
//                }
//                return false;
//            }
//        });
    }

    @OnClick({R.id.main_publish_question_icon, R.id.main_publish_question_text, R.id.main_publish_article_icon, R.id.main_publish_article_text,
            R.id.main_publish_video_icon, R.id.main_publish_video_text, R.id.main_publish_close})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.main_publish_question_icon:
            case R.id.main_publish_question_text:
                advance(AskActivity.class, AskActivity.COMING_TYPE_ASK);
                break;
            case R.id.main_publish_article_icon:
            case R.id.main_publish_article_text:
                advance(PublishArticleActivity.class);
                break;
            case R.id.main_publish_video_icon:
            case R.id.main_publish_video_text:
                advance(PublishVideoActivity.class);
                break;
        }
        exit();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        //outState.putString("title", title);
        super.onSaveInstanceState(outState);
    }

    @Override
    public void onResume() {
        super.onResume();
        setWindowHeight();
    }

    private void setWindowHeight() {
        WindowManager.LayoutParams p = getDialog().getWindow().getAttributes();
        p.width = RelativeLayout.LayoutParams.MATCH_PARENT;
        p.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
        p.dimAmount = 0;
        // p.gravity = Gravity.BOTTOM;
        // p.dimAmount = 0.8f;
        getDialog().getWindow().setAttributes(p);
    }
}
